import { dayjs } from 'element-plus';
// 生成随机车牌号的函数
export const generateRandomLicensePlate = () => {
	// const provinces = ['粤', '京', '沪', '津', '渝', '冀', '豫', '云', '辽', '黑', '湘', '皖', '鲁', '新', '苏', '浙', '赣', '鄂', '桂', '甘', '晋', '蒙', '陕', '吉', '闽', '贵', '粤', '青', '藏', '川', '宁', '琼']
	const provinces = ['川'];
	const letters = 'ABCDEFGHJKLMNPQRSTUVWXYZ';
	const numbers = '0123456789';

	const province = provinces[Math.floor(Math.random() * provinces.length)];
	const letter = letters[Math.floor(Math.random() * letters.length)];
	let licensePlate = province + letter;

	for (let i = 0; i < 5; i++) {
		licensePlate += numbers[Math.floor(Math.random() * numbers.length)];
	}

	return licensePlate;
};

// 生成随机时间的函数
export const generateRandomTime = () => {
	const now = new Date();
	const randomHours = Math.floor(Math.random() * 24);
	const randomMinutes = Math.floor(Math.random() * 60);
	now.setHours(now.getHours() - randomHours);
	now.setMinutes(now.getMinutes() - randomMinutes);
	return dayjs(now).format('YYYY/MM/DD HH:mm');
};

export const generateFluctuatingAltitude = (baseValue = 500, range = 100) => {
	const fluctuation = (Math.random() - 0.5) * 2 * range;
	return (baseValue + fluctuation).toFixed(1);
};

/**
 * 光照强度级别判断
 * @param {number} intensity - 光照强度值(lux)
 * @returns {number} 级别 (1-9级)
 */
export const getLightLevel = (intensity) => {
	if (intensity < 0) return 1;
	if (intensity < 10) return 1; // 黑暗
	if (intensity < 50) return 2; // 微光
	if (intensity < 200) return 3; // 低光照
	if (intensity < 1000) return 4; // 中等光照
	if (intensity < 5000) return 5; // 充足光照
	if (intensity < 10000) return 6; // 强光照
	if (intensity < 25000) return 7; // 很强光照
	if (intensity < 50000) return 8; // 极强光照
	return 9; // 烈日/极端强光
};

/**
 * 根据风速计算风力等级
 * @param {number} speed - 风速 (m/s)
 * @returns {number} 风力等级 (0-12级)
 */
export const getWindLevel = (speed) => {
	if (speed < 0.3) return 0;
	if (speed < 1.6) return 1;
	if (speed < 3.4) return 2;
	if (speed < 5.5) return 3;
	if (speed < 8.0) return 4;
	if (speed < 10.8) return 5;
	if (speed < 13.9) return 6;
	if (speed < 17.2) return 7;
	if (speed < 20.8) return 8;
	if (speed < 24.5) return 9;
	if (speed < 28.5) return 10;
	if (speed < 32.7) return 11;
	if (speed < 37.0) return 12;
	return 13;
};

/**
 * 根据风向角度判断风向
 * @param {number} degree - 风向角度 (0-360度)
 * @returns {object} 包含风向图标和文本的对象
 */
export const wind_direction_degree = (degree) => {
	let windIcon = '右上';
	let text = '右上';
	if (degree < 45) {
		windIcon = '右上';
		text = '右上';
	}
	if (degree > 45 && degree < 135) {
		windIcon = '右';
		text = '右';
	}
	if (degree > 135 && degree < 225) {
		windIcon = '左';
		text = '左';
	}
	if (degree > 225 && degree < 315) {
		windIcon = '左上';
		text = '左上';
	}
	if (degree > 315) {
		windIcon = '右上';
		text = '右上';
	}
	return { windIcon: windIcon, text: text };
};
